package com.ruoyi.web.controller.fund;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.refund.domain.HouseRefundT;
import com.ruoyi.refund.service.IHouseRefundTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 缴费信息Controller
 * 
 * @author lijie
 * @date 2023-04-24
 */
@RestController
@RequestMapping("/fund/refund")
public class HouseRefundTController extends BaseController
{
    @Autowired
    private IHouseRefundTService houseRefundTService;

    /**
     * 查询缴费信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseRefundT houseRefundT)
    {
        startPage();
        List<HouseRefundT> list = houseRefundTService.selectHouseRefundTList(houseRefundT);
        return getDataTable(list);
    }

    /**
     * 导出缴费信息列表
     */
    @Log(title = "缴费信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseRefundT houseRefundT)
    {
        List<HouseRefundT> list = houseRefundTService.selectHouseRefundTList(houseRefundT);
        ExcelUtil<HouseRefundT> util = new ExcelUtil<HouseRefundT>(HouseRefundT.class);
        util.exportExcel(response, list, "缴费信息数据");
    }

    /**
     * 退款缴费信息
     */
    @Log(title = "缴费信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{costId}/{refundDate}")
    public AjaxResult remove(@PathVariable Long costId,@PathVariable("refundDate") Date refundDate)
    {
/*            HouseRefundT houseRefundVO = houseRefundTService.selectHouseRefundTByCostId(costId);
            if ("0".equals(houseRefundVO.getCheckSts())) {
                return AjaxResult.error("未对账不可以做退款");
        }*/
        int costid2 = houseRefundTService.deleteHouseRefundTByCostIds(costId,getUsername(),refundDate);
        if(costid2==2){
            return AjaxResult.error("所剩余额不足不允许退款！");
        }
        HouseCostT houseCostVO = new HouseCostT();
        houseCostVO.setCostId(Long.valueOf(costid2));
        return AjaxResult.success(houseCostVO);

    }
    /*退款凭证*/
    @GetMapping(value = "getNote/{costId}")
    public AjaxResult getNote(@PathVariable("costId") Long costId)
    {
        HouseRefundT houseRefundVO = houseRefundTService.selectHouseRefundNote(costId);
        return AjaxResult.success(houseRefundVO);
    }
}
